package com.cpj.bsyyzx.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpj.bsyyzx.entity.GoToRegister;
import com.cpj.bsyyzx.entity.NContent;
import com.cpj.bsyyzx.entity.NurseClass;
import com.cpj.bsyyzx.service.INurseClassService;
import com.cpj.bsyyzx.util.CommonResult;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;



/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/nurseClass")
@Log4j
public class NurseClassController {


    @Autowired
    INurseClassService nurseClassService;


    @RequestMapping("/list")
    CommonResult list(Page page, NurseClass nurseClass){
        log.debug("分页查询");
        System.out.println(nurseClass);
        Page<NurseClass> rpage=nurseClassService.pageList(page, nurseClass);
        return CommonResult.success(rpage);
    }


    @RequestMapping("save")
    @ResponseBody
    CommonResult save(NurseClass nurseClass) {
        log.debug("保存");
        System.out.println(nurseClass);
        boolean success = nurseClassService.saveOrUpdate(nurseClass);
        return CommonResult.success(success);
    }

    @RequestMapping("toedit")
    @ResponseBody
    public CommonResult toedit(ModelMap map, Integer nId) {
        log.debug("跳转到修改页面");
        NurseClass nurseClass = nurseClassService.getById(nId);
        System.out.println(nurseClass);
        return CommonResult.success(nurseClassService.getById(nId));
    }

    @RequestMapping("delete/{nId}")
    @ResponseBody
    CommonResult delete(@PathVariable Integer nId) {
        log.debug("根据主键删除:" + nId);
        boolean success = nurseClassService.removeById(nId);
        return  CommonResult.success(success);
    }

    /**
     *
     * @return
     */
    @RequestMapping("getAllList")
    CommonResult getAllList(){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("status","启用");
        return CommonResult.success(nurseClassService.list(wrapper));
    }
}


